const express = require('express');
const cors = require('cors');
const axios = require('axios');

const app = express();
const port = 3000;

app.use(cors());
app.use(express.json());
app.use(express.static('public'));

app.post('/api/query', async (req, res) => {
    try {
        const { query } = req.body;
        
        const response = await axios.post('http://localhost:5000/process_query', {
            query: query,
            top_k: 3
        });
        
        // 直接传递Python服务的响应
        res.json(response.data);
    } catch (error) {
        console.error('Error:', error);
        res.status(500).json({
            error: 'Internal server error',
            message: error.message
        });
    }
});

app.listen(port, () => {
    console.log(`Server running at http://localhost:${port}`);
});
